import { ConfigEnv, defineConfig, loadEnv } from "vite";
import vue from "@vitejs/plugin-vue";
import { resolve } from "path";
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";
// https://vitejs.dev/config/
export default ({ mode, command }: ConfigEnv) => {
  console.log("command", command, loadEnv(mode, process.cwd()));
  return defineConfig({
    base: loadEnv(mode, process.cwd()).VITE_BASE,
    build: {
      minify: "terser",
      terserOptions: {
        compress: {
          drop_console: true,
          drop_debugger: false,
        },
      },
    },
    server: {
      port: 61998,
      open: false,
      host: true,
      proxy: {
        "/dev-api": {
          target: "http://localhost:3000/",
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/dev-api/, ""),
        },
      },
    },
    css: {
      preprocessorOptions: {
        // 引入公用的样式
        scss: {
          additionalData: `@use "@/style/variable.module.scss" as *;`,
        },
      },
    },
    resolve: {
      alias: {
        "@": resolve(__dirname, "src"),
      },
      extensions: [".js", ".json", ".ts"],
    },
    plugins: [
      vue(),
      AutoImport({
        resolvers: [ElementPlusResolver()],
      }),
      Components({
        resolvers: [ElementPlusResolver()],
      }),
    ],
  });
};
